<template>
    <view>
        <form action="">
            <view class="weui-cells weui-cells_after-title">
                <!-- <view class="weui-cell weui-cell_active">
                    <view class="weui-cell__hd">
                        <view class="weui-label">头像</view>
                    </view>
                    <view class="weui-uploader__file" style="right: 190rpx">
                        <image class="weui-uploader__img" src="/static/images/jurassic_user.png" mode="aspectFill" />
                    </view>
                </view> -->
                <view class="weui-cell weui-cell_active">
                    <view class="weui-cell__hd">
                        <view class="weui-label">昵称：</view>
                    </view>
                    <view class="weui-cell__bd">
                        <input class="weui-input" v-model="userInfo.nickname" placeholder-class="weui-input__placeholder" placeholder="修改昵称"  />
                    </view>
                </view>
                <view class="weui-cell weui-cell_active">
                    <view class="weui-cell__hd">
                        <view class="weui-label">性别：</view>
                    </view>
                   
                        <radio-group name="gender" @change="radioChange">
                            <label style="padding: 10rpx">
                                <radio value="0" />
                                男
                            </label>
                            <label style="padding: 50rpx">
                                <radio value="1" />
                                女
                            </label>
                        </radio-group>
             
                </view>
                <view class="weui-cell weui-cell_active">
                    <view class="weui-cell__hd">
                        <view class="weui-label">简介：</view>
                    </view>
                    <view class="weui-cell__bd">
                        <input class="weui-input" v-model="userInfo.introduction" placeholder-class="weui-input__placeholder"  placeholder="请输入简介" />
                    </view>
                </view>
            </view>
            <view class="btn-area" style="background-color: #f5f5f5; margin-top: 50rpx">
                <button class="submit_btn" formType="submit" @tap="updateInfo(userInfo)">确认提交</button>
            </view>
        </form>
    </view>
</template>

<script>
// pages/user/profile/profile.js
export default {
    data() {
        return {
			userInfo:''
		};
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
			var that = this;
		    uni.getStorage({
		    key: 'userInfo',
		    success: function (res) {
		        
		        that.setData({
					userInfo:res.data,
				})
				console.log("res.data");
		    }
		    });
		    this.userInfo = that.userInfo
			console.log(this.userInfo);
			
		  },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {},
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {},
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {},
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {},
    methods: {
		radioChange(e) {
		    console.log('radio发生change事件，携带value值为：', e.detail.value)
			this.userInfo.gender = e.detail.value
		  },
		updateInfo(userInfo){
			console.log("dayin");
			console.log(this.userInfo.sessionId);
			this.$sessionid = uni.getStorage("sessionId");
			uni.request({
				url:this.$baseUrl + '/user/update',
				method:'POST',
				header:{
					"session":"shadow-test",					'Accept': 'application/json',					"Content-Type":"application/json",
				},
				data:{
					userInfo
				},
				success: res=> {
					console.log(res)
					if(res.statusCode == 200){
						uni.showToast({
						  title: '更新成功',
						  icon: 'success',
						})
						setTimeout(()=>{
							uni.navigateBack({
								delta:1,//返回层数，2则上上页
							})
						},1000)
						
					}else{
						uni.showToast({
						  title: res.data.errorCode,
						  icon: 'error',
						})
					}
					
				},
				fail :(e)=>{
					console.log(e)
					uni.showToast({
					  title: '更新失败',
					  icon: 'error',
					})
				}
			})
			
		},
	}
};
</script>
<style>
@import './profile.css';
</style>
